package com.fx.zmlzml.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fx.zmlzml.entity.PcMemory;
import com.fx.zmlzml.mapper.PcMemoryMapper;
import com.fx.zmlzml.service.PcMemoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 电脑内存条 Service实现类
 * 实现电脑内存条相关的业务逻辑
 */
@Service
public class PcMemoryServiceImpl extends ServiceImpl<PcMemoryMapper, PcMemory> implements PcMemoryService {
    
    private static final Logger logger = LoggerFactory.getLogger(PcMemoryServiceImpl.class);

    @Override
    public List<PcMemory> getListByParams(Integer maxPrice, Integer minPrice) {
        logger.info("查询所有内存条列表，查询条件：maxPrice={}, minPrice={}", maxPrice, minPrice);
        List<PcMemory> list = baseMapper.getListByParams(maxPrice, minPrice);
        logger.info("内存条总条数：{}", list.size());
        return list;
    }

    @Override
    public boolean save(PcMemory entity) {
        logger.info("保存电脑内存条信息，制造商：{}", entity.getManufacturer());
        try {
            boolean result = super.save(entity);
            if (result) {
                logger.debug("保存电脑内存条成功，ID：{}", entity.getId());
            } else {
                logger.warn("保存电脑内存条失败，制造商：{}", entity.getManufacturer());
            }
            return result;
        } catch (Exception e) {
            logger.error("保存电脑内存条异常，制造商：{}", entity.getManufacturer(), e);
            throw e;
        }
    }
    
    @Override
    public boolean updateById(PcMemory entity) {
        logger.info("更新电脑内存条信息，ID：{}", entity.getId());
        try {
            boolean result = super.updateById(entity);
            if (result) {
                logger.debug("更新电脑内存条成功，ID：{}", entity.getId());
            } else {
                logger.warn("更新电脑内存条失败，ID：{}", entity.getId());
            }
            return result;
        } catch (Exception e) {
            logger.error("更新电脑内存条异常，ID：{}", entity.getId(), e);
            throw e;
        }
    }
    
    @Override
    public boolean removeById(Serializable id) {
        logger.info("删除电脑内存条，ID：{}", id);
        try {
            boolean result = super.removeById(id);
            if (result) {
                logger.debug("删除电脑内存条成功，ID：{}", id);
            } else {
                logger.warn("删除电脑内存条失败，ID：{}", id);
            }
            return result;
        } catch (Exception e) {
            logger.error("删除电脑内存条异常，ID：{}", id, e);
            throw e;
        }
    }
    
}